﻿public class ErrorNormalCtrl : CSIMediator
{
    private ErrorNormalPanel view;
    private ObjData errorData;

    private TweenPosition tPos;
    private TweenAlpha tAlpha;
    
    public override void SetData(params object[] args)
    {
        errorData = (ObjData)args[0];
    }
    
    public override void Awake()
    {
        base.Awake(); OnFinished();
        view = new ErrorNormalPanel(Go);
        tPos = Go.GetComponent<TweenPosition>();
        tAlpha = Go.GetComponent<TweenAlpha>();
    }

    public override void Open()
    {
        base.Open();
        var table_GlobalError= TableDataMgr.GlobalErrorMgr.GetItemById(errorData.objId);
        if (table_GlobalError == null)
        {
            EDebug.LogError(errorData.objId.ToString() + "错误码未配置");
            return;
        }
        view.Info_txt.text = DBSystemMgr.GetSingleton().GetStringByID(table_GlobalError.ContentId, errorData.strArg);
        ZMgr.SoundMgr.PlaySound(table_GlobalError.SoundId);
    }

    public override void Close()
    {
        base.Close(); 
    }

    public override void Destroy()
    {
        view = null;
        errorData = null;
        tPos = null;
        tAlpha = null;
        base.Destroy();
    }

    public override void AddListener()
    {
        EventDelegate.Add(tPos.onFinished, OnFinished);
    }

    public override int PanelId
    {
        get { return (int)PanelID.ErrorNormalPanel; }
    }

    private void OnFinished()
    {
        Utility.SetActive(view.Go, false);
    }
}